package com.yanqu.road.server.logic.activity.condition.normal;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.args.WineShopRankArgs;
import com.yanqu.road.entity.wineshop.WineShopRankActivityData;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseRankActivityCondition;

import java.math.BigInteger;
import java.util.Map;

public class BeautyEscortAddExpRankCondition extends BaseRankActivityCondition {

    public BeautyEscortAddExpRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.BeautyEscortAddExpRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.BeautyEscortAddExpRank.getValue(), handle);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        long value = 0L;
        if (object instanceof WineShopRankArgs) {
            WineShopRankArgs wineShopRankArgs = (WineShopRankArgs) object;
            for (Map.Entry<Integer, WineShopRankActivityData> entry : wineShopRankArgs.getActivityDataMap().entrySet()) {
                if (activityInfo.getActivityId() == entry.getKey()) {
                    value = entry.getValue().getMoney();
                    entry.getValue().setMoney(0);
                }
            }
        } else {
            value = (long) object;
        }
        setValue(getValue().add(BigInteger.valueOf(value)));
        rankChange();
    }
}
